﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Common;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MapComponentSprite
{
    public class MapBuildingLayerSprite : UserControlledSprite
    {
        /// <summary>
        /// 地图上的所有建筑物
        /// </summary>
        private List<BuildingUnitSprite> _buildingUnitSprites;

        public MapBuildingLayerSprite()
        {
            if (_buildingUnitSprites == null)
                BuildingUnitSprite.LoaMapUnitSpritesData();
            _buildingUnitSprites = BuildingUnitSprite.BuildingUnitSprites;
        }
        public override void Draw(GameTime gameTime)
        {
            foreach (var b in _buildingUnitSprites)
            {
                if (GameScreen.IsPositionInScreen(b.Building.Position) && !MapBackgroundLayerSprite.PositionOutOfMap(b.Building.Position))
                    b.Draw(gameTime);
            }
        }

        public override void Update(GameTime gameTime)
        {
            foreach (var b in _buildingUnitSprites)
            {
                if (GameScreen.IsPositionInScreen(b.Building.Position) && !MapBackgroundLayerSprite.PositionOutOfMap(b.Building.Position))
                    b.Update(gameTime);
            }
        }

    }
}
